<template>
  <div class="record mx-5 my-5">
    <div>
      <el-table
        :data="list"
        :empty-text="loading.list ? '数据加载中' : '暂无数据'"
        cell-class-name="custom-row"
        header-row-class-name="custom-row"
        header-cell-class-name="custom-header"
      >
        <el-table-column label="变动前余额">
          <template #default="scope">
            <div>硬币：{{scope.row.coin_before}}</div>
            <div>砖石：{{scope.row.diamond_before}}</div>
          </template>
        </el-table-column>
        <el-table-column label="变动后余额">
          <template #default="scope">
            <div>硬币：{{scope.row.coin_after}}</div>
            <div>砖石：{{scope.row.diamond_after}}</div>
          </template>
        </el-table-column>
        <el-table-column label="变动数量"  prop="quantity"></el-table-column>
        <el-table-column label="变动类型">
          <template #default="scope">
            {{scope.row.exchange_type == 1 ? '支出':'收入'}}
          </template>
        </el-table-column>
        <el-table-column label="备注"  prop="remarks"></el-table-column>
        <el-table-column label="时间">
          <template #default="scope">
            {{
            $dayjs.unix(scope.row.created_at).format("YYYY-MM-DD HH:mm:ss")
            }}
          </template>      
        </el-table-column>
      </el-table>
      <div class="d-flex my-5 justify-center">
        <el-pagination
          :page-size="10"
          :total="total"
          background
          hide-on-single-page
          layout="prev, pager, next"
          @current-change="currentChange"
        />
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, onMounted, reactive, toRefs } from "vue";
import { UserService } from "@/services/UserService";
import Empty from "@/components/empty/Index.vue";

export default defineComponent({
  name: "changeChargeRecord",
  components: { Empty },
  props: {},
  setup() {
    const state = reactive({
      list: [],
      total: null,
      loading: {
        list: false,
      },
    });

    onMounted(() => {
      getRechargeRecord();
    });
    const getRechargeRecord = async () => {
      state.loading.list = true;
      const res = await UserService.exchangeRecord().finally(() => {
        state.loading.list = false;
      });
      state.list = res.data.data.list;
      state.total = res.data.data.total;
    };

    const currentChange = async (val) => {
      state.currentPage = val;
      const res = await UserService.exchangeRecord({
        page: val,
      });

      state.list = res.data.data.list;
    };

    return {
      ...toRefs(state),
      currentChange,
    };
  },
});
</script>

<style lang="scss" scoped>
.recharge-record {
  width: 100%;
  position: relative;
  padding: 0 18px;
  box-sizing: border-box;
  min-height: 100%;

  .table {
    width: 98%;
    margin: 0 auto;

    .head {
      display: flex;
      justify-content: space-around;
      align-items: center;
      height: 60px;
      text-align: center;

      > div {
        color: #989898;
        font-size: 1.17em;
        font-weight: bold;
      }
    }

    .body {
      text-align: center;

      .row {
        height: 70px;
        color: #fff;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1rem;
        font-weight: 700;
        margin-bottom: 4px;

        .col {
          height: 68px;
          line-height: 68px;
          min-width: 25%;
          background-color: #2c2c32;
          margin-left: 0.5rem;

          &:first-child {
            margin-left: 0;
          }
        }
      }
    }
  }

  .recharge-type {
    width: 100%;
    height: 80px;
    margin: 0 auto;
    display: flex;
    border-bottom: 1px solid #4c4c53;

    > div {
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      color: #fff;
      width: 10rem;
      height: 100%;
      font-weight: 900;
      border-bottom: 3px solid transparent;
      color: #c0c0c2;
      margin-left: 30px;
    }

    .current {
      border-bottom-color: #7668cb;
      color: #7668cb;
    }
  }
}
</style>
